<!DOCTYPE html>
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>消息</title>
    <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport">
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="black" name="apple-mobile-web-app-status-bar-style">
    <meta content="telephone=no" name="format-detection">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link href="/css/likeHistory.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css">
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script>
        $(function () {
            //获取当前用户的id
            var user = JSON.parse(sessionStorage.getItem("user"));
            console.log(user);
            //获取所有系统消息
            $.get("/systemnotices/"+user.id+"/notice",{userId:user.id},function (data) {
                if(data.length === 0){
                    $(".aui-scrollView").html("<div class=\"aui-center\">\n" +
                        "            <span class=\"aui-center-title\">没有系统消息~</span>\n" +
                        "        </div>");
                }
                $(".aui-scrollView").renderValues({list:data}, {

                    getHref: function (item, value) {
                        var url = $(item).data("href");
                        $(item).attr("href", url + value);
                    },
                    doRead:function (item,value) {
                        //value是属性已读/未读
                        if(value==false){//未读
                            $(item).css("color","red");//设置样式
                        }
                    }
                });
                $(".notices").each(function (index, item) {
                    //从获取通知id
                    var id = $(item).data("id");

                    //绑定点击事件
                    $(item).click(function () {
                        $.ajax({
                            method: "PUT",
                            url: "/systemnotices/"+id+"/changeReadState",
                            data:{
                                id:id
                            },
                            success:function (data,json) {
                                console.log(data);

                            }
                        })
                        $(item).css("color","gray");
                        //location.href="/travelContent.html?id="+;
                        //window.location.reload();
                    });

                });
            });
        });
    </script>
</head>
<body>

<section class="aui-flexView">
    <header class="aui-navBar aui-navBar-fixed b-line">
        <a href="/mine/message.html" class="aui-navBar-item">
            <i class="icon icon-return"></i>
        </a>
        <div class="aui-center">
            <span class="aui-center-title">我的系统消息</span>
        </div>
        <a href="javascript:;" class="aui-navBar-item">
        </a>
    </header>

    <section class="aui-scrollView">
        <div class="aui-list-box" render-loop="list">
            <div class="aui-flex" id="readclick">
                    <div class="aui-flex-logo">
                        <img src="/upload/6610317b-2077-4bd3-98c7-7d31b6613469.jpg">
                    </div>
                <div class="aui-flex-box">
                    <a render-key="list.travel.id" render-fun="getHref" data-href="/travelContent.html?id=">
                        <h2>
                            <span style="font-size: 12px"  render-html="list.message"></span>
                        </h2>
                         <h3 render-html="list.travel.title" render-key="list.readstate" render-fun="doRead" render-attr="data-id=list.id" class="notices">
                         </h3>
                         <span>点击查看</span>
                    </a>
                </div>
                <span class="aui-flex-add" render-html="list.createTime"></span>
            </div>
        </div>
    </section>
</section>

</body></html>